<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .login-box {
            width: 500px;
            height: 500px;
            margin: 50px auto;
        }

        .login-box .title {
            font-weight: bold;
            line-height: 80px;
            text-align: center;
        }

        .login-box .block {
            margin: 30px 0;
        }

        .login-box .block input {
            height: 40px;
            padding-left: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
            width: 100%;
            outline: none;
            box-sizing: border-box;
            border-radius: 10px;
        }
        .login-box .dl{
            background-color: rgb(92, 92, 240);
            color: white;
        }
        .login-box span{
            margin-left: 400px;
        }
    </style>
</head>
<body>
    <div class="login-box">
        <div class="title">登录页</div>
        <div class="block">
            <input type="text" placeholder="手机号/用户名/邮箱">
        </div>
        <div class="block">
            <input type="password" placeholder="输入密码">
        </div>
        <div>
            <span><a href="">忘记密码？</a></span>
        </div>
        <div class="block">
            <input type="button" value="登陆" class="dl">
        </div>
    </div>
</body>
</html>
<script src="./Promise重新封装ajax函数.js"></script>
<script>
    //先获取三个input标签
    let inputs = document.querySelectorAll('input')
    //给登录的那个input绑定点击事件
    inputs[2].onclick = function(){
        //对表单内容做校验（为空校验，格式校验）
        if( inputs[0].value && inputs[1].value ){
            //校验密码为任意的四个数字
            ///^1[3-9]\d{9}$/.test(inputs[0].value) && /^\w{1,}@[0-9a-z]{1,}\.(com|cn|org)$/.test(inputs[0].value) && /^\w{4,}$/.test(inputs[0].value)
            if( /^\d{4}$/.test(inputs[1].value) ){
                ajax( 'get' , 'https://yantianfeng.com/api/login' , { username:inputs[0].value , password:inputs[1].value }).then( (user)=>{
                    console.log(user);
                    if( user.status == 200 ){
                        alert('登录成功！')
                    }
                    else{
                        alert('登录失败！')
                    }
                } )
            }
            else{
                alert('请输入正确的手机号/用户名/邮箱')
            }
        }
        else{
            alert('用户名/密码不能为空!')
        }
    }
</script>